package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.StoneShapeMapper;
import com.gxa.zhonglong.pojo.StoneShape;
import com.gxa.zhonglong.service.StoneShapeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneShapeService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneShapeServiceImpl implements StoneShapeService {

    @Autowired
    private StoneShapeMapper stoneShapeMapper;


    @Override
    public Boolean addStoneShape(StoneShape stoneShape) throws BusinessException {
        StoneShape stoneShape1 = stoneShapeMapper.selectStoneShapeyByCode(stoneShape.getShapeCode());
        if (stoneShape1 == null) {
            stoneShapeMapper.addStoneShape(stoneShape);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneShape(List<Long> ids) throws BusinessException {
        if(stoneShapeMapper.deleteStoneShape(ids)<1){
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }

    @Override
    public Boolean updateStoneShape(StoneShape stoneShape) throws BusinessException {
        Boolean aBoolean = stoneShapeMapper.updateStoneShape(stoneShape);
        if (aBoolean) {
            return true;
        }
        throw  new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<StoneShape> getStoneShapeList() {
        List<StoneShape> stoneShapes = stoneShapeMapper.selectStoneShape();
        return stoneShapes;
    }
}
